package de.shortys.myhome.api.view.components.toolbar;

import static de.java.shortys.utils.view.ViewUtils.getIconFromString;

import java.awt.BorderLayout;
import java.awt.Cursor;
import java.awt.Dimension;
import java.util.Observable;

import javax.swing.ImageIcon;
import javax.swing.JLabel;

import de.shortys.myhome.api.view.components.JImagePanel;
import de.shortys.myhome.api.view.event.listener.ActivationListener;

public class ApplicationToolbarItem extends AbstractToolbarItem {

	private static final ImageIcon BACKGROUND_IMAGE = getIconFromString("de/shortys/myhome/api/view/images/toolbarItem_Background.png");

	private static final long serialVersionUID = 1L;

	private String text;

	private JImagePanel backgroundPane;

	private ImageIcon icon;

	private JLabel logoLabel;

	public ApplicationToolbarItem(ImageIcon icon) {
		this(icon, null);
	}

	public ApplicationToolbarItem(ImageIcon icon, String text) {
		this.text = text;
		this.icon = icon;
		initialize();
	}

	private void initialize() {
		getContentPane().setLayout(new BorderLayout());
		getContentPane().setCursor(new Cursor(Cursor.HAND_CURSOR));
		getContentPane().setPreferredSize(new Dimension(50, 50));
		getContentPane().setOpaque(false);

		backgroundPane = new JImagePanel(BACKGROUND_IMAGE);
		backgroundPane.setLayout(new BorderLayout());

		logoLabel = new JLabel(icon);
		logoLabel.setToolTipText(text);
	}

	@Override
	public void addActivationListener(ActivationListener listener) {
		logoLabel.addMouseListener(listener);
	}

	@Override
	public void update(Observable o, Object arg) {
		// TODO Auto-generated method stub

	}

	@Override
	protected void buildComponents() {
		getContentPane().add(backgroundPane);
		backgroundPane.add(logoLabel);
	}

	@Override
	public void clear() {
		// TODO Auto-generated method stub
		
	}
}
